<%@page import="java.util.*" import="java.sql.ResultSet" import="java.sql.Statement" import="java.sql.Connection" import="connection.DBConnection" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Stock Master Creation</title>

<script language="javascript" type="text/javascript">

function check()
{
	var st1,st2,st3,st4,st5;
	
  	var namevalid=/^[a-zA-Z ]+$/;
  

        st1= document.f3.stockname.value;
        if(st1.length==0)
        {
        	alert("Enter Stock Item Name");
            return false;
      	}
/*        else if(st1.search(namevalid)==-1)
        {
            alert("Please Enter valid name");
            document.f3.stockname.value="";
            document.f3.stockname.focus();
            
	         return false;
    	 }
*/        
        st2= document.f3.stockgroup.value;
        if(st2.length==0)
        {
        	alert("Enter Group Name");
            return false;
      	}
  
	      st4= document.f3.stockunits.value;
          if(st4.length == 0) 
          {
              alert("Please Enter Units");
              return false;
          }
		
         if(!st4.match(/^\d+$/))
       	 {
        	 alert("Please Enter Units in Numerics only");
             return false;
       	 }
         
         st5= document.f3.stopeningbalance.value;

         if(st5.length == 0)
         {
              alert("Please Enter Opening Balance");
              return false;
         }
              return true;
    }

   </script>

</head>
<body>

<form name="f3"  action="StockMasterServlet" ONSUBMIT="return check()">
<center> <h2> Stock Master</h2></center>

<table border=0 align="center">


<tr>
	<td> Name of the Item </td>
	<td> <input type="text" name="stockname"></td>
</tr>

<tr>
	<td> Group </td>
	<td> <input type="text" name="stockgroup"></td>
</tr>

<tr>
	<td> Stock Code </td>
	
				<%	DBConnection dbc=new DBConnection();	
				 	Connection con=dbc.getNewConnection();
				 	String code2="ST1";
			
			        Statement st = null;
					ResultSet rs = null;
		
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select stcode from StockMaster"); %>
       		   
       		 <%  while(rs.next()) 
       		 	{ 
       				String code1=rs.getString(1);
       				
       			   String[] part = code1.split("(?<=\\D)(?=\\d)");
	   		       
	   		       String p0=part[0];		       
	   		       int p1=Integer.parseInt(part[1]);
	   		      
	   		       p1++;
	   		       
	   		       code2=p0+""+p1;

            	} 
            		%>
  
	 		<% }
		   catch(Exception e){} %>
	
	<td> <input type="text" name="stockcode" value="<%=code2 %>"></td>
</tr>

<tr>
	<td> Units </td>
	<td> <input type="text" name="stockunits"></td>
</tr>

<tr>
	<td> Opening Balance </td>
	<td> <input type="text" name="stopeningbalance"></td>
</tr>

<tr>
	
	<td> <input type="submit" name="enter" value="Submit"> </td>
</tr>

</table>
</form>
	
</body>
</html>